package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamInvigilation;
import com.ruoyi.exam.service.IExamInvigilationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监考分配管理Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/exam/invigilate")
public class ExamInvigilationController extends BaseController
{
    @Autowired
    private IExamInvigilationService examInvigilationService;

    /**
     * 查询监考分配管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamInvigilation examInvigilation)
    {
        startPage();
        List<ExamInvigilation> list = examInvigilationService.selectExamInvigilationList(examInvigilation);
        return getDataTable(list);
    }

    /**
     * 导出监考分配管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:export')")
    @Log(title = "监考分配管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamInvigilation examInvigilation)
    {
        List<ExamInvigilation> list = examInvigilationService.selectExamInvigilationList(examInvigilation);
        ExcelUtil<ExamInvigilation> util = new ExcelUtil<ExamInvigilation>(ExamInvigilation.class);
        util.exportExcel(response, list, "监考分配管理数据");
    }

    /**
     * 获取监考分配管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:query')")
    @GetMapping(value = "/{invigeId}")
    public AjaxResult getInfo(@PathVariable("invigeId") Long invigeId)
    {
        return success(examInvigilationService.selectExamInvigilationByInvigeId(invigeId));
    }

    /**
     * 新增监考分配管理
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:add')")
    @Log(title = "监考分配管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamInvigilation examInvigilation)
    {
        return toAjax(examInvigilationService.insertExamInvigilation(examInvigilation));
    }

    /**
     * 修改监考分配管理
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:edit')")
    @Log(title = "监考分配管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamInvigilation examInvigilation)
    {
        return toAjax(examInvigilationService.updateExamInvigilation(examInvigilation));
    }

    /**
     * 删除监考分配管理
     */
    @PreAuthorize("@ss.hasPermi('exam:invigilate:remove')")
    @Log(title = "监考分配管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invigeIds}")
    public AjaxResult remove(@PathVariable Long[] invigeIds)
    {
        return toAjax(examInvigilationService.deleteExamInvigilationByInvigeIds(invigeIds));
    }
}
